// localStorage hook函数
export function useStorage(key: string, value?: any): any {
  if (typeof value !== 'undefined') {
    try {
      window.localStorage.setItem(key, JSON.stringify(value))
    } catch (error) {
      window.localStorage.setItem(key, value)
    }
    return true
  }
  let str = window.localStorage.getItem(key)
  if (str) {
    try {
      str = JSON.parse(str)
    } catch (error) {
      return str
    }
  }
  return str
}
